# -*- coding:utf-8 -*-
from heuristics.sqr_min import *
from heuristics.Pile_Division import *
from search.all import *
from multi_robot_problem import MultiRobotState
from time import *
from problem_generator import ProblemGenerator
import re
from matplotlib.pyplot import hist, show, plot, subplot, title
from scipy.stats import wilcoxon
"""
Created on Apr 11, 2011

@author: bob
"""
def getResults(filename):
    _file = open(filename)
    _line = 'line_astar_man'
    _list = []
    max_sol = -infinity
    while (_line != ''):
        _line = _file.readline()
        _m = re.match("[0-9]+[ \t]Found[ \t]([0-9]+)", _line)
        if not _m is None:
            length = int(_m.group(1))
            _list.append(length)
            max_sol = max(length, max_sol)
        else:
            _list.append(None)
    _file.close()
    return _list,max_sol

def fillNone(intList, maxVal):
    for i in range(0, len(intList)):
        if intList[i] is None:
            intList[i] = maxVal
    return intList    
    
base_path = 'C:\\Users\\bob\\Desktop\\ai\\hard\\'
suff = '_30_hard.txt'
filename_astar_man = base_path + 'output_astar_man' + suff
filename_astar_pile = base_path + 'output_astar_pile' + suff
filename_gbf_man = base_path + 'output_gbf_man' + suff
filename_gbf_pile = base_path + 'output_gbf_pile' + suff

astar_man_list, astar_man_max = getResults(filename_astar_man)
astar_pile_list, astar_pile_max = getResults(filename_astar_pile)
gbf_man_list, gbf_man_max = getResults(filename_gbf_man)
gbf_pile_list, gbf_pile_max = getResults(filename_gbf_pile)

max_sol = max(astar_man_max, astar_pile_max, gbf_man_max, gbf_pile_max)

#set all the places with None to max_sol
astar_man_list = fillNone(astar_man_list, max_sol)
astar_pile_list = fillNone(astar_pile_list, max_sol)
gbf_man_list = fillNone(gbf_man_list, max_sol)
gbf_pile_list = fillNone(gbf_pile_list, max_sol)        
        


subplot(411)
hist(astar_man_list,70)
title('astar with obst. man. for 30s')

subplot(412)
hist(astar_pile_list,70)
title('astar with pile div. for 30s')

subplot(413)
hist(gbf_man_list,70)
title('gbf with obst. man. for 30s')

subplot(414)
hist(gbf_pile_list,70)
title('gbf with pile div. for 30s')
show()
print wilcoxon(astar_man_list, gbf_man_list)